﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RooHui.OA.Biz;
using RooHui.Tool;
using RooHui.Infrastructure.Entities.Entity;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Admin.Web.Controllers
{
    public class ProjectPublishController : Controller
    {
        //
        // GET: /ProjectPublish/

        public ActionResult Index()
        {
            return View();
        }
         
        public ActionResult GetProjectListForPublish(int page, int pageSize, int guaranteeCompanyID = -1, string key = "")
        {
            int count = 0;
            var projectList = ProjectPublishBiz.GetProjectListForPublish(page, pageSize, guaranteeCompanyID, key, System.Web.HttpContext.Current.User.Identity.Name, ref count);

            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("Rows", projectList);
            dic.Add("Total", count);
            return Content(dic.ToJson());
        }

        public ActionResult ProjectPublish(int projectID)
        {
            var project = ProjectAuditBiz.GetProjectByIDForAudit(projectID);
            //var processDoing = ProcessDoingBiz.GetProcessDoingByProjectID(projectID);
            //var processStepList = ProcessStepDoingBiz.GetProcessStepDoingList(projectID, processDoing.ProcessID);
            var processDoingHistoryList = ProcessDoingHistoryBiz.GetProcessDoingHistoryList(projectID);
            var repaymentPlanList = RepaymentPlanBiz.BuildRepaymentPlan(projectID);
             
            ViewBag.project = project;
            
            ViewBag.processDoingHistoryList = processDoingHistoryList;
            ViewBag.repaymentPlanList = repaymentPlanList;
            return View();
        }
        [HttpPost]
        public ActionResult AddMemberForPublish(int projectID, string userName, string realName, 
            string idCardNo, string handPhone, string address)
        {
            int flag = ProjectPublishBiz.AddMemberForPublish(projectID, userName, realName, idCardNo, handPhone, address,System.Web.HttpContext.Current.User.Identity.Name);
            return Content(flag.ToString());
        }

        [HttpPost]
        public ActionResult ProjectPublish(int projectID, DateTime realeseTime, DateTime beginDate, DateTime borrowInterestDate)
        {
            int flag = ProjectPublishBiz.ProjectPublish(projectID, realeseTime, beginDate, borrowInterestDate);
            return Content(flag.ToString());
        }

        [HttpPost]
        public ActionResult AddMemberAccount(int projectID)
        {
            var project = new Project().Find(projectID.ToString());
            var account = new Account();
            account.UserName = project.BorrowerName;
            account.Platfrom = AccountPlatfrom.HuiFu;
            account.BalanceAmount = 0;
            account.FrozenAmount = 0;
            account.PostAdd();
            return Content("1");

        }
    }
}
